<template>
  <a-form @submit="handleSubmit" :form="form" class="form">
    <a-row class="form-row" :gutter="16">
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="许可证类">
          <a-select :disabled="disabled" placeholder="请选择许可证类型" v-decorator="[ 'licencetype', {rules: [{ required: false, message: '请选择许可证类型'}]} ]">
            <a-select-option v-for="item in licenceTypeData" :key="item.id" :value="item.id">{{item.label}}</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="许可证号">
          <a-input
            :disabled="disabled"
            placeholder="请输入许可证号"
            v-decorator="[
              'licenceno',
                  {rules: [{ required: false, message: '请输入许可证号', whitespace: true}]}
            ]" />
        </a-form-item>
      </a-col>
    </a-row>
    <a-form-item v-if="showSubmit">
      <a-button htmlType="submit" >Submit</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
  import {getLicencelistInfo} from '@/api/organization';
export default {
  name: 'LicenceListForm',
  props: {
    showSubmit: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      disabled: false,
      licenceTypeData: [{id: '1', label: '域名根服务器运行机构许可证'}, {id: '2', label: '域名注册管理机构许可证'},
        {id: '3', label: '域名注册服务机构许可证'}, {id: '4', label: '增值电信业务经营许可证'}, {id: '5', label: '否'}],
      id: ''
    }
  },
  mounted() {
  },
  methods: {
    getDetail(obj) {
      const {type, value} = obj
      if (type === 'view') {
        this.disabled = true
        this.getInfo(JSON.parse(value).gnrlid)
      } else if (type === 'edit') {
        this.disabled = false;
        this.getInfo(JSON.parse(value).gnrlid)
      } else if (type === 'add') {
        this.disabled = false;
        this.form.resetFields()
        this.id = ''
      }
    },
    getInfo(gnrlid) {
      let that = this
      getLicencelistInfo(gnrlid).then(res => {
        const data = res.data
        that.$nextTick(()=>{
          setTimeout(() =>{
            that.id = data.id
            that.form.setFieldsValue(data)
          },0)
        });
      });
    },
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$notification['error']({
            message: 'Received values of form:',
            description: values
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
